package com.example.administrator.student4;

import android.app.Fragment;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;

public class grade extends AppCompatActivity {
    Spinner sp_subject,sp_class,sp_term,spinner;
    Button add;
    String name,subject,term,class_a;
    Fragment f1,f2,f3;
    TextView btn1;
    final static String arr_model[] = {"根据学生和课程","根据学生和学期","根据班级和课程"};
    @Override
    protected void onCreate(final Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.grade);
        btn1 = (TextView) findViewById(R.id.textView38);
        f1 = new SearchNameAndSubject();
        f2 = new SearchPersonAndTerm();
        f3 = new SearchByClassAndSubject();
        getFragmentManager().beginTransaction().add(R.id.linearLayout2,f1).commit();
        spinner = (Spinner) findViewById(R.id.model);
        ArrayAdapter<String> adapter_spinner = new ArrayAdapter<>(grade.this,android.R.layout.simple_expandable_list_item_1,arr_model);
        spinner.setAdapter(adapter_spinner);
        spinner.setSelection(0);
        btn1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(grade.this,AddAcitvity.class);
                startActivity(intent);
            }
        });
        spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                switch (position){
                    case 0: getFragmentManager().beginTransaction().replace(R.id.linearLayout2,f1).commit();
                        return;
                    case 1:getFragmentManager().beginTransaction().replace(R.id.linearLayout2,f2).commit();
                        return;
                    case 2: getFragmentManager().beginTransaction().replace(R.id.linearLayout2,f3).commit();
                }
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
        });

    }
}
